<template>
    <div class="order-view">
        <el-button type="primary" size="small" icon="el-icon-plus" @click="AddGoodUnitButton">新增</el-button>
        <el-drawer title="单位添加" :before-close="handleClose" :visible.sync="addVisible" direction="rtl"
            custom-class="demo-drawer" ref="drawer">
            <div class="demo-drawer__content">
                <el-form>
                    <el-form-item label="单位名称: " prop="unitName" :label-width="formLabelWidth">
                        <el-input v-model="unitName" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div class="demo-drawer__footer" align="center">
                    <el-button @click="addVisible = false">取 消</el-button>
                    <el-button type="primary" @click="addUnit">提交</el-button>
                </div>
            </div>
        </el-drawer>
    </div>
</template>
<script>
export default {
    name: "AddCustomer",
    data() {
        return {
            addVisible: false,
            unitName: '',
            formLabelWidth: '80px'
        };
    },
    mounted() {
    },
    methods: {
        handleClose() {
            this.addVisible = false;
        },

        addUnit() {
            if (this.unitName === '') {
                alert('请输入单位名称');
                return;
            }
            this.$http.post("http://localhost:8086/addUnit", {
                    createBy: 1,
                    unitName: this.unitName
                })
                .then((res) => {
                    if (res.data.code == '200') {
                        alert(res.data.message);
                        this.unitName = '';
                        this.handleClose();
                        this.$emit('childClick');
                    }else{
                        alert(res.data.message);
                    }
                })
        },

        //新增按钮
        AddGoodUnitButton() {
            this.addVisible = true;
        },
    },
};
</script>

<style lang="scss"></style>
